package af.fx.control.hyperlink;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @Description
 * @Author AF
 * @Version 1.0.0
 * @Date 2024/1/30
 */
public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        VBox vBox = new VBox();
        // html的一个标签样式
        Hyperlink hyperlink = new Hyperlink("www.baidu.com", new Button("网址"));
        
        hyperlink.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                HostServices hostServices = getHostServices();
                hostServices.showDocument(hyperlink.getText());
            }
        });
        
        vBox.getChildren().add(hyperlink);

        Scene scene = new Scene(vBox);
        primaryStage.setScene(scene);
        primaryStage.setHeight(800);
        primaryStage.setWidth(800);
        primaryStage.show();
    }
}
